<template>
  <el-container class="home-container">
    <!--头部区域-->
    <el-header>
      <div>
        <img src="../../assets/img/logo.jpg" class="logo-style">
        <span>后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <!--侧边栏-->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">
          |||
        </div>
        <!--菜单-->
        <el-menu background-color="#373d44" text-color="#fff" active-text-color="#409EFF" unique-opened
                 :collapse="isCollapse" :collapse-transition="false" router :default-active="activePath">
          <!--一级菜单-->
          <el-submenu index="1">
            <!--一级菜单的模板区-->
            <template slot="title">
              <!--图标-->
              <i class="el-icon-video-camera"></i>
              <!--文本-->
              <span>系统监控</span>
            </template>
            <!--二级菜单-->
            <el-menu-item index="/druid" @click="savePath('/druid')">
              <template slot="title">
              <!--图标-->
              <i class="el-icon-menu"></i>
              <!--文本-->
              <span>SQL监控</span>
            </template></el-menu-item>
          </el-submenu>

          <el-submenu index="2">
            <!--一级菜单的模板区-->
            <template slot="title">
              <!--图标-->
              <i class="el-icon-unlock"></i>
              <!--文本-->
              <span>权限管理</span>
            </template>
            <!--二级菜单-->
            <el-menu-item index="/users" @click="savePath('/users')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>组长分配</span>
              </template>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="3">
            <!--一级菜单的模板区-->
            <template slot="title">
              <!--图标-->
              <i class="el-icon-price-tag"></i>
              <!--文本-->
              <span>项目管理</span>
            </template>
            <!--二级菜单-->
            <el-menu-item index="/addGroup" @click="savePath('/addGroup')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>项目组管理</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/adminPlan" @click="savePath('/adminPlan')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>项目计划</span>
              </template>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="4">
            <!--一级菜单的模板区-->
            <template slot="title">
              <!--图标-->
              <i class="el-icon-document-copy"></i>
              <!--文本-->
              <span>文件管理</span>
            </template>
            <!--二级菜单-->
            <el-menu-item index="/adminUploadFile" @click="savePath('/adminUploadFile')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>文件上传</span>
              </template>
            </el-menu-item>
            <!--二级菜单-->
            <el-menu-item index="/getAdminDailyFile" @click="savePath('/getAdminDailyFile')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>日常文件</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/getAdminProjectFile" @click="savePath('/getAdminProjectFile')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>项目文件</span>
              </template>
            </el-menu-item>

          </el-submenu>

          <el-submenu index="5">
            <!--一级菜单的模板区-->
            <template slot="title">
              <!--图标-->
              <i class="el-icon-reading"></i>
              <!--文本-->
              <span>图书管理</span>
            </template>
            <el-menu-item index="/getAdminBook" @click="savePath('/getAdminBook')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>图书信息</span>
              </template>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="6">
            <!--一级菜单的模板区-->
            <template slot="title">
              <!--图标-->
              <i class="el-icon-monitor"></i>
              <!--文本-->
              <span>数据统计</span>
            </template>
            <!--二级菜单-->
            <el-menu-item index="/getReport" @click="savePath('/getReport')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>数据汇总</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/getProjectInformation" @click="savePath('/getProjectInformation')">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>工程信息</span>
              </template>
            </el-menu-item>
          </el-submenu>

        </el-menu>
      </el-aside>

      <!--右侧主体内容-->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
    export default {
        name: "Main",
        data(){
          return {
            //是否进行菜单栏折叠,false代表不折叠
            isCollapse: false,
            //被激活的连接地址
            activePath: ''
          }
        },
        //生命周期函数
       created() {
          //为了设置当前按钮的被点击时，显示高亮
          this.activePath = window.sessionStorage.getItem('activePath');
       },
      methods: {
          logout(){
            //把本地的token清空
            window.sessionStorage.clear();
            //路由到登录页
            this.$router.push('/login')
          },
          /*实现菜单的折叠与展开*/
          toggleCollapse(){
            this.isCollapse = !this.isCollapse;

          },
          //保存链接的激活状态
          savePath(urlPath){
             window.sessionStorage.setItem('activePath',urlPath);
             this.activePath = urlPath;
          }
        }
    }
</script>

<style scoped lang="scss">
  .home-container{
    height: 100%;
  }
  .el-header{
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #ffffff;
    font-size: 20px;
    > div{
      display: flex;
      align-items: center;
      span{
        margin-left: 15px;
      }
    }
  }

  .el-aside {
    background-color: #373d44;
    .el-menu{
      border-right: none;
    }
  }

  .el-main {
    background-color: #E9EEF3;
  }
  .logo-style{
    height: 125px;
    width: 100px;
  }

  .toggle-button{
    background-color: #4A5064;
    font-size: 10px;
    line-height: 24px;
    color: #ffffff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }


</style>
